package com.pig4cloud.pig.trip.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.pig4cloud.pig.common.core.util.R;
import com.pig4cloud.pig.common.security.util.SecurityUtils;
import com.pig4cloud.pig.trip.Service.TrTripContentService;
import com.pig4cloud.pig.trip.api.entity.TrTrip;
import com.pig4cloud.pig.trip.api.entity.TrTripContent;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@RestController
@RequiredArgsConstructor
@RequestMapping("/tripContent")
@Tag(description = "tripContent", name = "行程单内容管理")
public class TrTripContentController {
	@Autowired
	private TrTripContentService trTripContentService;
	/**
	 * 添加行程单内容
	 */
	@PostMapping("/addTripContent")
	public R addTrip(@RequestBody TrTripContent trTripContent) {
		return R.ok(trTripContentService.insertTripContent(trTripContent));
	}
	/**
	 * 通过行程单ID查询对应的所有内容（支持多条数据）
	 *
	 * @param tripId 行程单ID（不能为空）
	 * @return 行程单内容列表
	 */
	@GetMapping("/trip-content/getByTripId")
	public R<List<TrTripContent>> getByTripId(@RequestParam Long tripId) {
		// 参数校验
		if (tripId == null) {
			System.out.println("行程单不能为空");
		}
		// 查询逻辑：通过tripId查询所有未删除的内容
		List<TrTripContent> contentList = trTripContentService.list(
				Wrappers.<TrTripContent>lambdaQuery()
						.eq(TrTripContent::getTripId, tripId)
						.eq(TrTripContent::getDelFlag, 0) // 假设0表示未删除
		);
		// 返回结果
		return R.ok(contentList);
	}
	/**
	 * 删除行程单内容
	 */
	@DeleteMapping("/deleteTripContent")
	public R deleteContentTrip(@RequestParam Long tripContentId) {
		return R.ok(trTripContentService.removeByContentId(tripContentId));
	}
	/**
	 * 修改行程单内容
	 */
	@PutMapping("/updateTripContent")
	public R updateTripContent(@RequestBody TrTripContent trTripContent) {
		return R.ok(trTripContentService.updateTripContent(trTripContent));
	}

}
